import { messages } from "share/common";
import React, { Component } from "react";
import { Button, Radio, Spin } from "antd";
import HotelServer from "../hotel-server";
import { message } from "antd/lib/index";
const RadioGroup = Radio.Group;

class SetOrderModel extends Component {
  constructor(props) {
    super(props);
    this.state = {
      orderModel: "normal", // 默认常规模式
      loading: false,
      hotelData: {}, // 返回的酒店设置数据
    };
  }

  componentWillMount() {
    this.initData();
  }

  initData = () => {
    HotelServer(this)
      .getPlatformModelData({ companyOid: this.props.companyOID })
      .then((res) => {
        let orderModel = res.data.body.bookMode ? res.data.body.bookMode : "normal";
        this.setState({ orderModel: orderModel, hotelData: res.data.body });
      });
  };

  onRadioGroupChange = (eve) => {
    this.setState({ orderModel: eve.target.value });
  };

  saveSetting = () => {
    const { hotelData, orderModel } = this.state;
    const paramsData = Object.assign({}, hotelData);
    paramsData.bookMode = orderModel;
    paramsData.companyOid = this.props.companyOID;
    HotelServer(this)
      .savePlatformModelData(paramsData)
      .then((res) => {
        if (res.data.success) {
          this.initData();
          message.success(messages("supplier-1.key355") /*保存成功*/);
        } else {
          message.error(res.data.message);
        }
      });
  };

  render() {
    const { orderModel, loading } = this.state;
    return (
      <div className="airline-config-container">
        <Spin spinning={loading}>
          <h2>{messages("supplier-1.key379") /*预订模式设置*/}</h2>
          <a>{messages("supplier-1.key380") /*提前审批模式：先选航班，审批通过出票*/}</a>
          <a className="a-line-bottom">
            {messages("supplier-1.key381") /*常规预订模式：事前审批，预订时需关联申请单*/}
          </a>
          <RadioGroup value={orderModel} onChange={this.onRadioGroupChange}>
            <Radio value="aia">{messages("supplier-1.key357") /*提前审批模式*/}</Radio>
            <Radio value="normal">{messages("supplier-1.key360") /*常规预订模式*/}</Radio>
          </RadioGroup>
          <br />
          <br />
          <Button type="primary" onClick={this.saveSetting}>
            {messages("supplier-1.key356") /*保存配置*/}
          </Button>
        </Spin>
      </div>
    );
  }
}

export default SetOrderModel;
